<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable style="width: 200px"
            @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="queryParams.phone" placeholder="请输入手机号" clearable style="width: 200px"
            @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-table border v-loading="loading" :data="noticeList" @selection-change="handleSelectionChange">
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column label="照片" width="100" align="center" prop="avatar">
          <template #default="scope">
            <el-image style="width: 50px; height: 50px;" :src="scope.row.avatar" :preview-src-list="[scope.row.avatar]"
              preview-teleported>
            </el-image>
          </template>
        </el-table-column>
        
        <el-table-column label="申请时间" align="center" prop="applyTime"  />
        <el-table-column label="姓名" align="center" prop="name"  />
        <el-table-column label="手机号码" align="center" prop="phone"  />
        <el-table-column label="状态" align="center" prop="status">
          <template #default="scope">
            <dict-tag :options="employee_apply_status" :value="scope.row.status" />
          </template>
        </el-table-column>


        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <!-- <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)">修改</el-button> -->
            <!-- <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)">删除</el-button> -->
            <el-button link type="primary" icon="Edit" @click="handleExamine(scope.row)">审核</el-button>
          </template>
        </el-table-column>
      </el-table>
  
      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.currentPage"
        v-model:limit="queryParams.pageSize" @pagination="getList" />
  
      <!-- 添加或修改管理员对话框 -->
      <el-dialog :title="title" v-model="open" width="700px" append-to-body>
        <el-form :model="form" :rules="rules" ref="noticeRef" label-position="right" label-width="90px">
          <!--  -->
          <el-row>
            <el-col :span="12">
              <el-form-item label="姓名" prop="name">
                <el-input v-model="form.name" placeholder="请输入姓名" maxlength="30" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="手机号码" prop="phone">
                <el-input v-model="form.phone" placeholder="请输入手机号码" maxlength="30" />
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row>
            <el-col :span="12">
              <el-form-item label="部门名称" prop="deptName">
                <el-input v-model="form.deptName" placeholder="请输入部门名称" maxlength="30" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="管理员职业" prop="occupation">
                <el-input v-model="form.occupation" placeholder="请输入管理员职业" maxlength="30" />
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row>
            <el-col :span="12">
              <el-form-item label="职务" prop="position">
                <el-input v-model="form.position" placeholder="请输入职务" maxlength="30" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="职称" prop="profession">
                <el-input v-model="form.profession" placeholder="请输入职称" maxlength="30" />
              </el-form-item>
            </el-col>
          </el-row>
  
          <el-row>
            <el-col :span="12">
              <el-form-item label="身份证正面" prop="idcardFront">
                <el-image :src="form.idcardFront" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="身份证反面" prop="idcardBack">
                <el-image :src="form.idcardBack" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="许可证" prop="occupationCert">
                <el-image :src="form.occupationCert" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="学历证书" prop="eduCert">
                <el-image :src="form.eduCert" />
              </el-form-item>
            </el-col>
          </el-row>
  
  
  
          <el-row>
            <el-col :span="12">
              <el-form-item label="职称证书" prop="professionCert">
                <el-image :src="form.professionCert" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="其他证件" prop="otherCert">
                <el-image :src="form.otherCert" />
              </el-form-item>
            </el-col>
          </el-row>
  
  
        </el-form>
        <template #footer>
          <div class="dialog-footer">
            <el-button type="primary" @click="submitForm">同 意</el-button>
            <el-button @click="cancel">拒 绝</el-button>
          </div>
        </template>
      </el-dialog>
  
  
    </div>
  </template>
  
  <script setup name="Notice">
  import {
    applyDetail,
    applyCheck,
    listEmployeeApply,
    getNotice,
    delNotice,
    addNotice,
    updateNotice,
  } from "@/api/sysUserApply/sysUserApply";
  const { proxy } = getCurrentInstance();
  const { sys_notice_status, sys_notice_type, sys_user_sex, occupation_status, employee_apply_status } = proxy.useDict(
    "sys_notice_status",
    "sys_notice_type",
    "sys_user_sex",
    "occupation_status",
    "employee_apply_status"
  )
  
  const sys_normal_disable = [
    {
      elTagClass: "",
      elTagType: "primary",
      label: "是",
      value: true,
    },
    {
      elTagClass: "",
      elTagType: "danger",
      label: "否",
      value: false,
    },
  ];
  
  const roleOptions = ref([]);
  const deptList = ref([]);
  const noticeList = ref([]);
  
  const open = ref(false);
  const loading = ref(true);
  const showSearch = ref(true);
  const ids = ref([]);
  const single = ref(true);
  const multiple = ref(true);
  const total = ref(0);
  const title = ref("");
  
  const data = reactive({
    form: {},
    queryParams: {
      currentPage: 1,
      pageSize: 10,
      name: undefined,
      phone: undefined,
      status: undefined,
    },
    rules: {
    },
  });
  
  const { queryParams, form, rules } = toRefs(data);
  
  /** 查询管理员列表 */
  function getList() {
    loading.value = true;
    listEmployeeApply(queryParams.value).then((response) => {
      noticeList.value = response.records;
      total.value = response.total;
      loading.value = false;
    });
  }
  
  /** 表单重置 */
  function reset() {
    form.value = {
      "deptId": 0,
      "roleIds": 0,
      "sysUserReplyId": 0,
      "isAdmin": undefined,
      "isBandh": undefined,
      "name": "",
      "occupation": undefined,
      "position": "",
      "profession": "",
    };
    proxy.resetForm("noticeRef");
  }
  
  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.currentPage = 1;
    getList();
  }
  
  /** 重置按钮操作 */
  function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
  }
  
  /** 多选框选中数据 */
  function handleSelectionChange(selection) {
    ids.value = selection.map((item) => item.sysUserReplyId);
    single.value = selection.length != 1;
    multiple.value = !selection.length;
  }
  
  /** 新增按钮操作 */
  function handleAdd() {
    reset();
    open.value = true;
    title.value = "添加管理员";
  }
  
  /**修改按钮操作 */
  function handleUpdate(row) {
    reset();
    const sysUserReplyId = row.sysUserReplyId || ids.value;
    getNotice(sysUserReplyId).then((response) => {
      form.value = response;
      roleOptions.value = response.roles
      deptList.value = response.deptList
      open.value = true;
      title.value = "修改管理员";
    });
  }
  
  /** 删除按钮操作 */
  function handleDelete(row) {
    const sysUserReplyIds = row.sysUserReplyId || ids.value;
    proxy.$modal
      .confirm('是否确认删除管理员编号为"' + sysUserReplyIds + '"的数据项？')
      .then(function () {
        return delNotice(sysUserReplyIds);
      })
      .then(() => {
        getList();
        proxy.$modal.msgSuccess("删除成功");
      })
      .catch(() => { });
  }
  
  
  
  /** 取消按钮 */
  function cancel() {
    let data ={
      sysUserReplyId :form.value.sysUserReplyId,
      status :2,
    }
    open.value = false;
    applyCheck(data).then((response) => {
      proxy.$modal.msgSuccess("拒绝成功");
      open.value = false;
      getList();
    });
    reset();
  }
  
  /** 提交按钮 */
  function submitForm() {
    let data ={
      sysUserReplyId :form.value.sysUserReplyId,
      status :1,
    }
    applyCheck(data).then((response) => {
      proxy.$modal.msgSuccess("同意成功");
      open.value = false;
      getList();
    });
  }
  
  /* 审核 */
  async function handleExamine(row) {
    reset();
    const sysUserReplyId = row.sysUserReplyId || ids.value;
    applyDetail(sysUserReplyId).then((response) => {
      form.value = response;
      roleOptions.value = response.roles
      deptList.value = response.deptList
      open.value = true;
      title.value = "审核管理员";
    });
  
  }
  
  getList();
  </script>
  
  <style scoped>
  .el-image {
      width: 200px;
      height: 60px;
  }
  </style>